//
// Created by zsj on 2019/12/21.
//

#include "io.h"

string read_from_file(const string& file) {
    ifstream in(file.c_str(), ios::in | ios::binary);
    if (!in) {
        __err("找不到文件\"" + file + "\"。");
        return "";
    }

    char c;
    string buf;
    while (in.get(c)) {
        buf += c;
    }

    in.close();
    return buf;
}

void write_to_file(const string& file, const string& content) {
    ofstream out(file.c_str(), ios::out | ios::binary);

    if (!out) {
        __err("无法创建文件\"" + file + "\"。");
        return;;
    }

    out.write(content.c_str(), content.size());
    out.close();
}
